//T10078. 二叉树遍历
#include <iostream>
using namespace std;

string s1,s2;
int s1len,s2len;
void preorder(int k,int left,int right){//以中序遍历串s1的left至right为树的结点，在层遍历串s2的第k个位置开始找根
    while (k<s2len){
        char c=s2[k];
        int m=s1.find(c);
        if (!(m<left||m>right)){ //找到根
            cout<<c;
            if (m>left) preorder(k+1,left,m-1); //有左子树
            if (m<right) preorder(k+1,m+1,right);//有右子树
            break;
        }
        k++;
    }
}
int main(){
    cin>>s1>>s2;
    s1len=s1.length();
    s2len=s2.length();
    preorder(0,0,s1len-1);
}